package com.app.service;

import com.app.model.AlarmDataManager;
import com.app.model.AlarmDataManager.AlarmLoader;
import com.app.view_controller.AlarmRecevierActivity;
import com.app.view_controller.ContentActivity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class AlarmRecevier extends BroadcastReceiver {

	private static final String TAG = "ALARMRECEVIER";
	private static final boolean DEBUG = true;

	@Override
	public void onReceive(Context context, Intent intent) {
		//Get the alarm from the intent
		Bundle b = intent.getExtras();
		String AlarmId = b.getString(ContentActivity.ALARM_MESSAGE);
		AlarmDataManager mAlarm = AlarmLoader.getFromStorage(AlarmId, context);
		if (DEBUG)
			Log.d(TAG, "onReceive " + AlarmId + " valore alarm " + mAlarm.getAlarmId());
		if (mAlarm.isAlarmEneable()) {
			
			//Put the alarm data into a new Intent to pass to the service
			Intent newIntent = new Intent(context, AlarmService.class);
			newIntent.setAction(AlarmService.START_ALARM_SERVICE);
			newIntent.putExtra(ContentActivity.ALARM_MESSAGE, mAlarm.getAlarmId());
			context.startService(newIntent);
		}
	}

}
